package com.xbts.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xbts.common.utils.StringUtils;
import com.xbts.system.domain.CnCloudMarketSku;
import com.xbts.system.service.ICnCloudMarketTypeService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xbts.common.annotation.Log;
import com.xbts.common.core.controller.BaseController;
import com.xbts.common.core.domain.AjaxResult;
import com.xbts.common.enums.BusinessType;
import com.xbts.system.domain.CnCloudMarketType;
import com.xbts.system.service.ICnCloudMarketSkuService;
import com.xbts.common.utils.poi.ExcelUtil;
import com.xbts.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * 云市场类型Controller
 * @author xbts
 * @date 2023-10-10
 */
@Api("云市场类型")
@RestController
@RequestMapping("/system/market/type")
public class CnCloudMarketTypeController extends BaseController {

    @Autowired
    private ICnCloudMarketTypeService cnCloudMarketTypeService;

    /**
     * 查询云市场类型列表
     */
    @ApiOperation("查询云市场类型列表")
//    @PreAuthorize("@ss.hasPermi('system:marketType:list')")
    @GetMapping("/list")
    public AjaxResult selectCnCloudMarketTypeList() {
        return success(cnCloudMarketTypeService.selectCnCloudMarketTypeList());
    }

    /**
     * 查询云市场规格列表
     */
    @ApiOperation("查询云市场规格列表")
    @PreAuthorize("@ss.hasPermi('system:market:list')")
    @PostMapping("/getListByType")
    public TableDataInfo getListByType(@RequestBody CnCloudMarketType cnCloudMarketType) {
        startPage(cnCloudMarketType);
        return getDataTable(cnCloudMarketTypeService.list(new LambdaQueryWrapper<CnCloudMarketType>()
                .eq(StringUtils.isNotEmpty(cnCloudMarketType.getType()), CnCloudMarketType::getType, cnCloudMarketType.getType())));
    }

    /**
     * 查询云市场类型列表
     */
    @ApiOperation("查询云市场类型列表")
    @PreAuthorize("@ss.hasPermi('system:marketType:list')")
    @GetMapping("/typeList")
    public AjaxResult typeList() {
        return success(cnCloudMarketTypeService.typeList());
    }

    /**
     * 获取云市场类型详细信息
     */
    @ApiOperation("获取云市场类型详细信息")
    @ApiImplicitParam(name = "id", value = "云市场类型ID", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:marketType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(cnCloudMarketTypeService.selectCnCloudMarketTypeById(id));
    }

    /**
     * 新增云市场类型
     */
    @ApiOperation("新增云市场类型")
    @PreAuthorize("@ss.hasPermi('system:marketType:add')")
    @Log(title = "云市场类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody CnCloudMarketType cnCloudMarketType) {
        return toAjax(cnCloudMarketTypeService.insertCnCloudMarketType(cnCloudMarketType));
    }

    /**
     * 修改云市场类型
     */
    @ApiOperation("修改云市场类型")
    @PreAuthorize("@ss.hasPermi('system:marketType:edit')")
    @Log(title = "云市场类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody CnCloudMarketType cnCloudMarketType) {
        return toAjax(cnCloudMarketTypeService.updateCnCloudMarketType(cnCloudMarketType));
    }

    /**
     * 删除云市场类型
     */
    @ApiOperation("删除云市场类型")
    @ApiImplicitParam(name = "ids", value = "云市场类型ID集合", required = true, dataType = "String", paramType = "path", dataTypeClass=String.class)
    @PreAuthorize("@ss.hasPermi('system:marketType:remove')")
    @Log(title = "云市场类型", businessType = BusinessType.DELETE)
	@PostMapping("/batchDelete")
    public AjaxResult batchDelete(@RequestBody List<String> ids) {
        return toAjax(cnCloudMarketTypeService.deleteCnCloudMarketTypeByIds(ids));
    }
}
